#include "Camera.h"

namespace glow
{
  Vector3d Camera::getPosition(){
    return _position;
  }

  Vector3d Camera::getAngle(){
    return _angle;
  }

  Vector3d Camera::getTarget(){
    return _target;
  }

  void Camera::setPosition(Vector3d pos){
    _position = pos;
  }

  void Camera::setAngle(Vector3d ang){
    _angle = ang;
  }

  void Camera::setTarget(Vector3d targ){
    _target = targ;
  }


  Camera::Camera (Vector3d pos, Vector3d ang, Vector3d targ) : _position(pos), _angle(ang), _target(targ)
  {
    //_emgr = EventManager::getInstance();
  }

  Camera::Camera() { reset(); }

  Camera::~Camera(){}

  /*void Camera::getEvent()
  {
    EventManager _emgr = EventManager::getInstance();
    _emgr->getEvent();
    if(_emgr->isKeyDown('A'))
      _position.x+=pas;
    if(_emgr->isKeyDown('Z'))
      _position.y+=pas;
    if(_emgr->isKeyDown('E'))
      _position.z+=pas;
    if(_emgr->isKeyDown('R'))
      _angle.x+=pas;
    if(_emgr->isKeyDown('T'))
      _angle.y+=pas;
    if(_emgr->isKeyDown('Y'))
      _angle.z+=pas;
    if(_emgr->isKeyDown('U'))
      _focus.x+=pas;
    if(_emgr->isKeyDown('I'))
      _focus.y+=pas;
    if(_emgr->isKeyDown('O'))
      _focus.z+=pas;
      }*/
  // le code qui suit n a pas ete teste
  void Camera::reset(){
    Vector3d v(0,0,0);
    _position = v;
    _angle = v;
    _target = v;
  }

  void Camera::lookAt(Vector3d pos, Vector3d ang, Vector3d targ)
	{
	  _position = pos;
	  _angle = ang;
	  _target = targ;
	  gluLookAt(pos.x, pos.y, pos.z,targ.x, targ.y, targ.z, ang.x, ang.y, ang.z);
	}

    void Camera::translate(Vector3d v){
      Vector3d pos = _position;
      Vector3d ang = _angle;
      Vector3d targ = _target;
      reset();
      Vector3d new_pos = pos+v;
      _position = new_pos;
      _angle = ang;
      _target = targ;
    }

    void Camera::target(Vector3d v){
      Vector3d pos = _position;
      Vector3d ang = _angle;
      Vector3d targ = _target;
      reset();
      Vector3d new_targ = targ+v;
      _position = pos;
      _angle = ang;
      _target = new_targ;
    }

    void Camera::rotate(Vector3d v){
      Vector3d pos = _position;
      Vector3d ang = _angle;
      Vector3d targ = _target;
      reset();
      Vector3d new_angl = ang+v;
      _position = pos;
      _angle = new_angl;
      _target = targ;
    }

  void Camera::render(){
    lookAt(_position, _angle, _target);
  }

}
